package com.quanquan.store.repository;

import com.quanquan.store.entity.DailyReport;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 功能描述:me每日报表
 *
 * @ClassName: DailyReportRepository
 * @Author: xiaoqianh丶
 * @Date: 2019-07-02 10:16
 * @Version: V1.0
 */
public interface DailyReportRepository extends JpaRepository<DailyReport,String>, JpaSpecificationExecutor<DailyReport> {


    /**
     * 根据id查询报表信息
     * @param id
     * @param num
     * @return
     */
    public DailyReport findByIdAndRemove(String id, Integer num);

    /**
     * 根据商户id和日期查找提报记录
     * @param storeId
     * @param dateTime
     * @return
     */
    @Query(value = "select * from oo_daily_report where store_id = ?1 and create_time = ?2 and remove = 0",nativeQuery = true)
    DailyReport findByStoreIdAndDateTime(String storeId, String dateTime);


    /**
     * 查询所有
     * @return
     */
    @Query(value = "select * from oo_daily_report",nativeQuery = true)
    List<DailyReport> findAlls();

    /**
     * 查询商户对应所有
     * @return
     */
    @Query(value = "select * from oo_daily_report where store_id = ?1",nativeQuery = true)
    List<DailyReport> findByStoreId(String storeId);



    /**
     * 未提报商户
     *
     * @return
     */
    @Query(value = "SELECT store_name FROM oo_store WHERE id NOT IN (SELECT store_id FROM oo_daily_report WHERE create_time = DATE_SUB(CURDATE(),INTERVAL ?1 DAY)) AND status_show = 0 AND status_remove = 0",nativeQuery = true)
    List<String> findByStoreNoSupport(Integer day);

}
